package cn.wolfcode.edu.web.controller;

import cn.wolfcode.edu.domain.Classroom;
import cn.wolfcode.edu.query.QueryObject;
import cn.wolfcode.edu.service.IClassGradeService;
import cn.wolfcode.edu.service.IClassroomService;
import cn.wolfcode.edu.util.JsonResult;
import cn.wolfcode.edu.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by ASUS on 2018/7/8.
 */
@Controller
@RequestMapping("classroom")
public class ClassroomController {

    @Autowired
    private IClassroomService classroomService;
    @Autowired
    private IClassGradeService classGradeService;
    //页面定位
    @RequestMapping("")
    public String index(){
        return "classroom";
    }
    //教室列表
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(QueryObject qo){
        return classroomService.query(qo);
    }
    //教室保存
    @RequestMapping("save")
    @ResponseBody
    public JsonResult saveClassroom(Classroom classroom){
        JsonResult jsonResult = new JsonResult();
        try{
            classroomService.insertClassroom(classroom);
        }catch(Exception e){
            e.printStackTrace();
            jsonResult.setMsg("保存失败啦呀.....你个傻逼");
        }
        return jsonResult;
    }
    //教室编辑
    @RequestMapping("update")
    @ResponseBody
    public JsonResult updateClassroom(Classroom classroom){
        JsonResult jsonResult = new JsonResult();
        try{
            classroomService.updateClassroom(classroom);
        }catch(Exception e){
            e.printStackTrace();
            jsonResult.setMsg("编辑失败啦呀.....");
        }
        return jsonResult;
    }
    //查询所有教室
    @RequestMapping("listAll")
    @ResponseBody
    public List<Classroom> listAll(){

        return classroomService.selectAllClassroom();
    }
    //查询所有未启用的教室
    @RequestMapping("listAllClassroomExStatus")
    @ResponseBody
    public List<Classroom> listAllClassroomExStatus(){

        return classroomService.listAllClassroomExStatus();
    }
    //启用教室
    @RequestMapping("enableClassroom")
    @ResponseBody
    public JsonResult enableClassroom(Long id,Long statusNum){
        JsonResult jsonResult = new JsonResult();
        try{
            classroomService.enableClassroom(id,statusNum);
        }catch(Exception e){
            e.printStackTrace();
            jsonResult.setMsg("失败啦呀.");
        }
        return jsonResult;
    }
    //停用教室
    @RequestMapping("diasableClassroom")
    public String diasableClassroom(Long id){
        classGradeService.selectClassById(id);
        return "classroom";
    }
}
